Skip to content

fix(pnpm): rewrite pnpm commands with global flags before the subcommand - #3275

Open
breisnerlopez wants to merge 1 commit into
rtk-ai:developfrom
breisnerlopez:fix/pnpm-strip-global-opts
Open

fix(pnpm): rewrite pnpm commands with global flags before the subcommand#3275
breisnerlopez wants to merge 1 commit into
rtk-ai:developfrom
breisnerlopez:fix/pnpm-strip-global-opts

Conversation

@breisnerlopez

Copy link
Copy Markdown

Problem

The hook rewriter matches pnpm via a subcommand allowlist anchored right after pnpm (^pnpm\s+(exec|i|install|list|ls|outdated|run|run-script)), with no stripping of pnpm global options. So flag-first monorepo forms are never rewritten and stream raw:

command before
pnpm run build ✅ rewritten
pnpm -r install ❌ raw
pnpm --filter @app list ❌ raw
pnpm -w install ❌ raw

Fix

Add strip_pnpm_global_opts — a direct mirror of the existing strip_git_global_opts (#163) — that strips a fixed set of pnpm global options (-r/--recursive, -w/--workspace-root, --filter/-F) for classification only, in the same spot git is normalized in classify_command.

The rewrite step still operates on the original command text via strip_word_prefix, so:

  • an unknown flag (pnpm -x build) is not stripped → no match → no rewrite;
  • a flag-first form whose original doesn't match a rewrite prefix (pnpm -r lint) is a safe no-op, never a malformed rewrite.

rtk pnpm now accepts -r/-w as global flags and forwards them. They are appended after the subcommand (pnpm install -r), matching the established --filter handling — behavior-preserving, since these are root-level pnpm options accepted in either position (verified against pnpm 9.15.4: pnpm install --help lists them, and pnpm <flag> <sub> vs pnpm <sub> <flag> produce identical output and install scope for -r, -w, --filter).

Tests

16 new tests: flag-first rewrite forms (-r, --filter, -F, --filter=, -w, combos), no-regression on bare forms (pnpm install, pnpm run build, pnpm build still None), false-positive guards (unknown flag not stripped, --filter without subcommand, recursive-lint safe no-op), CLI parse tests, and the merge ordering.

cargo fmt --check, cargo clippy --all-targets, and cargo test all clean.

Note

The glued short filter form -F@app (no space) is not stripped; it falls back to the existing safe passthrough (no scope change), consistent with pre-existing behavior.

The hook rewriter matched pnpm via a subcommand allowlist anchored right
after `pnpm ` (`^pnpm\s+(install|list|...)`), so flag-first monorepo forms
were never rewritten and streamed raw:

  pnpm run build          -> rtk pnpm run build   (matched)
  pnpm -r install         -> (not rewritten)
  pnpm --filter @app list -> (not rewritten)
  pnpm -w install         -> (not rewritten)

Add `strip_pnpm_global_opts` (mirror of the existing `strip_git_global_opts`)
that strips a fixed set of pnpm global options (`-r`/`--recursive`,
`-w`/`--workspace-root`, `--filter`/`-F`) for CLASSIFICATION only. The rewrite
step still operates on the original text via `strip_word_prefix`, so an
unknown flag or a flag-first form with no matching rewrite prefix is a safe
no-op — never a malformed rewrite. `rtk pnpm` now accepts `-r`/`-w` globally
and forwards them.

The flags are forwarded after the subcommand (`pnpm install -r`), matching the
established `--filter` handling. This is behavior-preserving: they are
root-level pnpm options accepted in either position (verified against pnpm
9.15.4; `pnpm <flag> <sub>` and `pnpm <sub> <flag>` produce identical output
and install scope for `-r`, `-w`, and `--filter`).

Adds 16 tests: flag-first rewrite forms, no-regression on bare forms, and
false-positive guards (unknown flag not stripped, filter without subcommand,
recursive-lint safe no-op).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant